package com.smasher.update.component.download.sys

import android.app.DownloadManager.Request
import android.os.Environment
import androidx.core.net.toUri

class DownloadRequestBuilder(private val url: String) {

    private val request: Request

    init {
        val uri = url.toUri()
        this.request = Request(uri)
    }

    fun setTitle(title: String): DownloadRequestBuilder {
        request.setTitle(title)
        return this
    }

    fun setDescription(description: String): DownloadRequestBuilder {
        request.setDescription(description)
        return this
    }

    fun setMimeType(mimeType: String): DownloadRequestBuilder {
        request.setMimeType(mimeType)
        return this
    }

    fun allowScanningByMediaScanner(): DownloadRequestBuilder {
//        request.allowScanningByMediaScanner()
        return this
    }

    fun setNetworkType(networkType: Int): DownloadRequestBuilder {
        request.setAllowedNetworkTypes(networkType)
        return this
    }

    fun setNotificationVisibility(visibility: Int): DownloadRequestBuilder {
        request.setNotificationVisibility(visibility)
        return this
    }

    fun setDefaultDestination(subPath: String): DownloadRequestBuilder {
        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, subPath);
        return this
    }

    fun build(): Request {
        return request
    }

}
